package com.kungfuhacking.wristbandpro.my.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.kungfuhacking.wristbandpro.R;
import com.kungfuhacking.wristbandpro.base.view.BaseActivity;
import com.kungfuhacking.wristbandpro.utils.Constant;

/**
 * 修改性别
 * Created by Aaron on 17/5/12.
 */

public class ModifySexActivity extends BaseActivity implements View.OnClickListener {

    private ImageView cb_mal;
    private ImageView cb_femal;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_modify_sex);
        initWidget();
    }

    private void initWidget() {
        RelativeLayout rlfemal = (RelativeLayout) findViewById(R.id.rl_femal);
        cb_femal = (ImageView) findViewById(R.id.cb_femal);
        RelativeLayout rlmeal = (RelativeLayout) findViewById(R.id.rl_meal);
        cb_mal = (ImageView) findViewById(R.id.cb_mal);
        ImageView iv_left = (ImageView) findViewById(R.id.iv_left);
        TextView tv_right = (TextView) findViewById(R.id.tv_right);

        rlfemal.setOnClickListener(this);
        rlmeal.setOnClickListener(this);
        iv_left.setOnClickListener(this);
        tv_right.setOnClickListener(this);

        if ("女".equals(sp.getString(Constant.SEX, ""))) {
            cb_mal.setSelected(false);
            cb_femal.setSelected(true);
        } else {
            cb_mal.setSelected(true);
            cb_femal.setSelected(false);
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {

            case R.id.rl_femal:
                cb_mal.setSelected(false);
                cb_femal.setSelected(true);
                break;

            case R.id.rl_meal:
                cb_mal.setSelected(true);
                cb_femal.setSelected(false);
                break;

            case R.id.iv_left:
                finish();
                break;

            case R.id.tv_right://完成

                String sex = sp.getString(Constant.SEX, "");
                String mSex = cb_mal.isSelected() ? "男" : "女";

                if (mSex.equals(sex)) {
                    finish();
                    return;
                }

                Intent data = new Intent();
                data.putExtra("modifySex", mSex);
                setResult(0x0112, data);
                finish();

                break;

        }
    }
}
